package cn.ym.system.service.impl;

import cn.ym.basic.service.impl.BaseServiceImpl;
import cn.ym.basic.utils.AssertUtil;
import cn.ym.basic.utils.PageList;
import cn.ym.system.domain.Role;
import cn.ym.system.domain.Systemdictionarydetail;
import cn.ym.system.domain.Systemdictionarytype;
import cn.ym.system.mapper.SystemdictionarydetailMapper;
import cn.ym.system.mapper.SystemdictionarytypeMapper;
import cn.ym.system.query.SystemdictionarydetailQuery;
import cn.ym.system.service.SystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 业务层：数据字典明细
 */
@Service
public class SystemdictionarydetailServiceImpl  extends BaseServiceImpl<Systemdictionarydetail> implements SystemdictionarydetailService {

    @Autowired
    private SystemdictionarydetailMapper systemdictionarydetailMapper;

    @Autowired
    private SystemdictionarytypeMapper systemdictionarytypeMapper;
    /**
     * 添加
     * @param systemdictionarydetail
     */
    @Transactional//默认只读为false，默认传播机制为REQUIRED[有且仅有一个事务]
    @Override
    public void add(Systemdictionarydetail systemdictionarydetail) {
        //AssertUtil.isNotEmpty(systemdictionarydetail.getName(),"数据字典明细名称不能为空");
        systemdictionarydetailMapper.add(systemdictionarydetail);
    }

    /**
     * 修改
     * @param systemdictionarydetail
     */
    @Transactional//默认只读为false，默认传播机制为REQUIRED[有且仅有一个事务]
    @Override
    public void update(Systemdictionarydetail systemdictionarydetail) {
        //AssertUtil.isNotEmpty(systemdictionarydetail.getName(),"数据字典明细名称不能为空");

        systemdictionarydetailMapper.update(systemdictionarydetail);
    }


    /**
     * 查询指定types_id数据字典明细信息
     * @param id
     * @return
     */
    @Override
    public List<Systemdictionarydetail> loadqueryByTypesId(Long id) {
        //查询出所有字典类型
        Systemdictionarytype systemdictionarytype = systemdictionarytypeMapper.findOne(id);
        //查询指定types_id数据字典明细信息
        List<Systemdictionarydetail> systemdictionarydetails = systemdictionarydetailMapper.loadqueryByTypesId(id);
        for (Systemdictionarydetail systemdictionarydetail : systemdictionarydetails) {
            systemdictionarydetail.setSystemdictionarytype(systemdictionarytype);
        }
        return systemdictionarydetails;
    }

}
